columnview: Split gtk_column_view_allocate_columns
authorMatthias Clasen <mclasen@redhat.com>
Fri, 5 Jun 2020 15:24:55 +0000 (11:24 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 5 Jun 2020 15:27:40 +0000 (11:27 -0400)
Split off a helper function that just distributes
the widths, without actually allocating the columns.

This will be used in measuring in the future.

gtk/gtkcolumnview.c
gtk/gtkcolumnviewprivate.h

index 85da86d48292968eeb48b6986ae7f11516994ddd..46fb35714786eeba45ab00d1cf4ebaded5e1f28e 100644 (file)
@@ -236,19 +236,19 @@ gtk_column_view_measure (GtkWidget      *widget,
     }
 }
 
-static int
-gtk_column_view_allocate_columns (GtkColumnView *self,
-                                  int            width)
+void
+gtk_column_view_distribute_width (GtkColumnView    *self,
+                                  int               width,
+                                  GtkRequestedSize *sizes)
 {
   GtkScrollablePolicy scroll_policy;
-  int col_min, col_nat, extra, col_size, x;
+  int col_min, col_nat, extra, col_size;
   int n, n_expand, expand_size, n_extra;
   guint i;
-  GtkRequestedSize *sizes;
 
   n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
   n_expand = 0;
-  sizes = g_newa (GtkRequestedSize, n);
+
   for (i = 0; i < n; i++)
     {
       GtkColumnViewColumn *column;
@@ -282,7 +282,6 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
   else
     expand_size = n_extra = 0;
 
-  x = 0;
   for (i = 0; i < n; i++)
     {
       GtkColumnViewColumn *column;
@@ -300,6 +299,37 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
                   n_extra--;
                 }
             }
+          sizes[i].minimum_size = col_size;
+        }
+
+      g_object_unref (column);
+    }
+}
+
+static int
+gtk_column_view_allocate_columns (GtkColumnView *self,
+                                  int            width)
+{
+  guint i, n;
+  int x;
+  GtkRequestedSize *sizes;
+
+  n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
+
+  sizes = g_newa (GtkRequestedSize, n);
+
+  gtk_column_view_distribute_width (self, width, sizes);
+
+  x = 0;
+  for (i = 0; i < n; i++)
+    {
+      GtkColumnViewColumn *column;
+      int col_size;
+
+      column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
+      if (gtk_column_view_column_get_visible (column))
+        {
+          col_size = sizes[i].minimum_size;
 
           gtk_column_view_column_allocate (column, x, col_size);
           if (self->in_column_reorder && i == self->drag_pos)
index 8343c26144629ca03a9c3012bad10729a38e946e..2d080b9aa5d3b324a5bc3921fc517b235e6c1bf0 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "gtk/gtkcolumnview.h"
 #include "gtk/gtklistview.h"
+#include "gtk/gtksizerequest.h"
 
 #include "gtk/gtkcolumnviewsorterprivate.h"
 #include "gtk/gtklistitemwidgetprivate.h"
@@ -33,4 +34,8 @@ void                    gtk_column_view_measure_across          (GtkColumnView
                                                                  int                    *minimum,
                                                                  int                    *natural);
 
+void                    gtk_column_view_distribute_width        (GtkColumnView    *self,
+                                                                 int               width,
+                                                                 GtkRequestedSize *sizes);
+
 #endif  /* __GTK_COLUMN_VIEW_PRIVATE_H__ */